<script setup>
import { ref } from 'vue'
import { requireImg } from '@/utils/common'
const showPop = ref(true)
let lenged = ref([
  {
    name: '材料',
    value: 0,
    radio: 0
  },
  {
    name: '软件技术',
    value: 1,
    radio: 16.67
  },
  {
    name: '硬件组件',
    value: 5,
    radio: 83.33
  }
])
const optionData = {
  color: ['#2F9CFF', '#3CE4E8', '#FFF5A0', '#FFA478', '#FF7878'],
  tooltip: {
    trigger: 'item',
    borderColor: '#0F2638',
    backgroundColor: '#0F2638DB',
    textStyle: {
      color: '#fff',
      fontSize: 14
    },
    formatter: function (params) {
      return `<div>${params.name} ${params.value} 个</div>`
    }
  },
  graphic: {
    elements: [
      {
        type: 'image',
        z: 3,
        style: {
          image: requireImg('industry/echart_icon.png'),
          width: 88,
          height: 88
        },
        left: 'center',
        top: 'center'
      }
    ]
  },
  series: [
    {
      name: '',
      type: 'pie',
      clockWise: false,
      radius: [48, 60],
      center: ['50%', '50%'],
      hoverAnimation: true,
      itemStyle: {
        normal: {
          label: {
            show: false
          },
          labelLine: {
            show: false
          }
        }
      },
      data: lenged.value
    }
  ]
}
const option = ref(optionData)

const poptitle = ref('上游企业数量')
const setData = (title, lengeds) => {
  poptitle.value = title + '数量'
  showPop.value = true
  lenged.value = lengeds
  option.value.series[0].data = lengeds
}

defineExpose({
  setData
})
</script>

<template>
  <transition
    appear
    name="custom-classes-transition"
    enter-active-class="animate__animated animate__fadeIn"
    leave-active-class="animate__animated animate__fadeOut"
  >
    <div class="EnterpriseNumber" v-if="showPop">
      <p class="title">
        <span>{{ poptitle }}</span>
        <span @click="showPop = false"><img src="@img/industry/close.png" alt="" /></span>
      </p>
      <div class="echartbox">
        <div class="left">
          <Charts :option="option" container="1" />
        </div>
        <div class="right">
          <div :class="['item', 'item' + (index + 1)]" v-for="(item, index) in lenged" :key="index">
            <p>
              <span>{{ item.name }}</span>
            </p>
            <p>
              <NumberAnimate :count="item.value"></NumberAnimate>
              <span>/家</span>
            </p>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>
<style scoped lang="scss">
.EnterpriseNumber {
  width: 434px;
  height: 280px;
  background: url('@img/industry/pop_small.png');
  background-size: 100% 100%;

  .title {
    display: flex;
    justify-content: space-between;
    padding: 15px 15px 20px 55px;
    font-size: 18px;

    span:last-child {
      img {
        width: 20px;
        height: 20px;
        cursor: pointer;
      }
    }
  }

  .echartbox {
    width: 100%;
    padding: 0 10px;
    height: 210px;
    display: flex;
    align-items: center;

    .left {
      width: 160px;
      height: 160px;
      margin: 0 10px;
      background: center center url('@img/infrastructure/echart_bg.png') no-repeat;
      background-size: 100% 100%;
    }

    .right {
      flex: 1;
      height: 100%;
      margin-right: 10px;
      padding-top: 10px;
      display: flex;
      flex-wrap: wrap;
      .item {
        width: 112px;
        height: 72px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding-left: 20px;

        p:first-child {
          color: #85b9cb;

          span:last-child {
            margin-left: 5px;
          }
        }

        p:last-child {
          font-family: DINAlternate;
          font-size: 23px;
          margin-top: 10px;

          span {
            margin-left: 5px;
            color: #2897ff;
            font-size: 14px;
            font-family: PingFang;
          }
        }

        &.item1 {
          background: left url('@img/infrastructure/lenged01.png') no-repeat;
          background-size: 15px 72px;
        }

        &.item2 {
          background: left url('@img/infrastructure/lenged02.png') no-repeat;
          background-size: 15px 72px;
        }

        &.item3 {
          background: left url('@img/infrastructure/lenged03.png') no-repeat;
          background-size: 15px 72px;
        }

        &.item4 {
          background: left url('@img/infrastructure/lenged04.png') no-repeat;
          background-size: 15px 72px;
        }

        &.item5 {
          background: left url('@img/infrastructure/lenged05.png') no-repeat;
          background-size: 15px 72px;
        }
      }
    }
  }
}
</style>
